import { ref, onMounted } from 'vue'

import { onBeforeRouteUpdate, useRoute } from 'vue-router'

import { getCateGoryAPI } from '@/apis/category'

export const useCateGory = () => {
  const route = useRoute()

  const cateList = ref({})

  const getcateData = async (id = route.params.id) => {
    const res = await getCateGoryAPI(id)

    cateList.value = res.result
  }

  onBeforeRouteUpdate((to) => {
    getcateData(to.params.id)
  })

  onMounted(() => getcateData())

  return {
    cateList
  }
}
